package xyz.qduwo.servlet.manager;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import xyz.qduwo.dao.CategoryDao;
import xyz.qduwo.entity.CatgoryEntity;
import xyz.qduwo.util.RespUtils;

/**
 *
 * @author Accelerator
 */
@WebServlet("/admin/manager/AddType")
public class AddType extends HttpServlet{
    
    CatgoryEntity catgory = new CatgoryEntity();

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("application/x-json;charset=utf-8");
        
        int type_num = Integer.parseInt(req.getParameter("type_num"));
        String type = req.getParameter("type");
        int num = Integer.parseInt(req.getParameter("num"));
        
        catgory.setId(type_num);
        catgory.setName(type);
        catgory.setIsShow(num);
        
        try{
            CategoryDao.save(catgory);
            resp.getWriter().println(RespUtils.success());
        }catch(Exception ex){
            ex.printStackTrace();
            resp.getWriter().println(RespUtils.fail("添加失败"));
        }
    }
    
}